<nz-tabset
  class="top-tabs-wrap"
  nzType="card"
  [nzHideAll]="true"
  [nzTabBarStyle]="{
    'margin': '0'
  }"
  [(nzSelectedIndex)]="tabsIndex"
  (nzSelectChange)="tabsChange($event)">
  <nz-tab
    *ngFor="let tab of searchTabs"
    [nzTitle]="tab.label"
  ></nz-tab>
</nz-tabset>

<!-- S search -->
<app-search-bar
  #SearchRef
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  labelFlex="100px"
  (onSearch)="queryResetData($event)"
  (onReset)="queryResetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-4">
  <div class="opera-wrap">
    <button
      nz-button
      nzType="primary"
      [nzLoading]="exportLoading"
      (click)="exportTable()"
    >导出</button>

    <!-- <button
      nz-button
      nzType="primary"
      nzDanger
      class="m-l-8"
      (click)="showPaymentModal()"
    >打款失败</button> -->

    <button
      nz-button
      nzType="primary"
      class="m-l-8"
      (click)="subPayment(2)"
    >发放补贴</button>
  </div>

  <div class="pagination-wrap-position p-t-10">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
      (nzCurrentPageDataChange)="onCurrentPageDataChange($event)"
    >
      <thead>
        <tr>
          <th
            nzWidth="50px"
            nzLeft
            [(nzChecked)]="checked"
            [nzIndeterminate]="indeterminate"
            (nzCheckedChange)="onAllChecked($event)"
          ></th>
          <th nzAlign="center" nzWidth="180px" nzLeft>销售订单号</th>
          <th nzAlign="center" nzWidth="120px">实付款</th>
          <th nzAlign="center" nzWidth="120px">销售订单状态</th>
          <th nzAlign="center" nzWidth="180px">旧机订单号</th>
          <th nzAlign="center" nzWidth="140px">预估回收款总计</th>
          <th nzAlign="center" nzWidth="150px">预估以旧换机补贴</th>
          <th nzAlign="center" nzWidth="140px">实际回收款总计</th>
          <!-- <th nzAlign="center" nzWidth="120px">账户类型</th> -->
          <!-- <th nzAlign="center" nzWidth="160px">收款账号</th> -->
          <!-- <th nzAlign="center" nzWidth="150px">收款人</th> -->
          <th nzAlign="center" nzWidth="150px">实际以旧换机补贴</th>
          <th nzAlign="center" nzWidth="120px">补贴状态</th>
          <th nzAlign="center" nzWidth="170px">更新时间</th>
          <th nzAlign="center" nzWidth="280px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <td
            nzLeft
            [nzChecked]="setOfCheckedId.has(data.id)"
            (nzCheckedChange)="onItemChecked(data.id, $event)"
          ></td>
          <!-- 销售订单号 -->
          <td nzAlign="center" nzLeft>
            <ng-container *ngIf="tabsIndex === 0; else elsesdTemplate">
              <!-- 配件 -->
              <a
                style="color: #409EFF;"
                target="_blank"
                [routerLink]="['/order/accDetails', data.saleOrderId]"
              >
                {{ data.saleOrderNum || '-' }}
              </a>
            </ng-container>
            <ng-template #elsesdTemplate>
              <!-- 二手 -->
              <a
                style="color: #409EFF;"
                target="_blank"
                routerLink="/used-store/usedOrderDetails"
                [queryParams]="{id: data.saleOrderId}"
              >
                {{ data.saleOrderNum || '-' }}
              </a>
            </ng-template>
          </td>
          <!-- 实付款 -->
          <td nzAlign="center">{{ data.saleOrderPrice || '-' }}</td>
          <!-- 销售订单状态 -->
          <td nzAlign="center">
            <ng-container *ngIf="tabsIndex === 0; else elseStTemplate">
              <!-- 配件 -->
              <span [ngStyle]="{'color': data.saleOrderStatus | partsOrderStatus: 'color'}">
                {{ data.saleOrderStatus | partsOrderStatus: 'label' }}
              </span>
            </ng-container>
            <ng-template #elseStTemplate>
              <!-- 二手 -->
              <span [ngStyle]="{'color': data.saleOrderStatus | secondOrderStatus: 'color'}">
                {{ data.saleOrderStatus | secondOrderStatus: 'label' }}
              </span>
            </ng-template>
          </td>
          <!-- 旧机订单号 -->
          <td nzAlign="center">
            <ng-container *ngIf="data.recycleOrderNum; else elserodTemplate">
              <a
                style="color: #409EFF;"
                target="_blank"
                routerLink="/aisi-recyc/loveOrderManage"
                [queryParams]="{okey: data.recycleOrderNum}"
              >
                {{ data.recycleOrderNum || '-' }}
              </a>
            </ng-container>
            <ng-template #elserodTemplate>
              -
            </ng-template>
          </td>
          <!-- 预估回收款总计 -->
          <td nzAlign="center">{{ data.estimatePrice || '-' }}</td>
          <!-- 预估以旧换机补贴 -->
          <td nzAlign="center">{{ data.estimateAllowance || '-' }}</td>
          <!-- 实际回收款总计 -->
          <td nzAlign="center">{{ data.actualPrice || '-' }}</td>
          <!-- 账户类型 -->
          <!-- <td nzAlign="center">
            <ng-container [ngSwitch]="data.payway">
              <span *ngSwitchCase="111" style="color: #67C23A;">
                微信
              </span>
              <span *ngSwitchCase="121" style="color: #409EFF;">
                支付宝
              </span>
              <span *ngSwitchDefault>-</span>
            </ng-container>
          </td> -->
          <!-- 收款账号 -->
          <!-- <td nzAlign="center">{{ data.payacc || '-' }}</td> -->
          <!-- 收款人 -->
          <!-- <td nzAlign="center">{{ data.payname || '-' }}</td> -->
          <!-- 实际以旧换机补贴 -->
          <td nzAlign="center">
            <span style="color: #F56C6C;">
              {{ data.actualAllowance || '-' }}
            </span>
          </td>
          <!-- 补贴状态 -->
          <td nzAlign="center">
            {{ data.status | financeOrderChangeStatus }}
          </td>
          <!-- 更新时间 -->
          <td nzAlign="center">{{ data.updateTime || '-' }}</td>
          <!-- 操作 -->
          <td nzAlign="center" nzRight>
            <!-- *ngIf="data.saleOrderStatus === 9 && data.status === 0" -->
            <button
              *ngIf="data.saleOrderStatus === 9 && data.status === 0"
              nz-button
              nzType="link"
              nzSize="small"
              (click)="generateSubsidies(data)"
            >生成补贴</button>

            <!-- *ngIf="data.saleOrderStatus === 9 && data.status === 1" -->
            <button
              *ngIf="data.saleOrderStatus === 9 && data.status === 1"
              nz-button
              nzType="link"
              nzSize="small"
              (click)="generateSubsidies(data)"
            >重新生成补贴</button>

            <!-- <button
              nz-button
              nzType="link"
              nzSize="small"
              (click)="showCollectionModal(data)"
            >编辑收款信息</button> -->
            
            <button
              nz-button
              nzType="link"
              nzSize="small"
              (click)="followModal(data)"
            >跟进</button>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>

<!-- S 修改收款信息 Modal -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isCollectionVisible"
  [nzTitle]="'修改收款信息'"
  (nzOnCancel)="isCollectionVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <form nz-form [formGroup]="collectionForm">
        <nz-form-item>
          <nz-form-label [nzSpan]="5" nzRequired>收款账号</nz-form-label>
          <nz-form-control [nzSpan]="19" nzErrorTip="请输入收款账号!">
            <input
              nz-input
              formControlName="payacc"
              placeholder="请输入收款账号"
            />
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label [nzSpan]="5" nzRequired>收款人姓名</nz-form-label>
          <nz-form-control [nzSpan]="19" nzErrorTip="请输入收款人姓名!">
            <input
              nz-input
              formControlName="payname"
              placeholder="请输入收款人姓名"
            />
          </nz-form-control>
        </nz-form-item>
      </form>
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="default" (click)="isCollectionVisible = false">取消</button>
        <button nz-button nzType="primary" [nzLoading]="collectionLoading" (click)="subCollection()">确定</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- E 修改收款信息 Modal -->

<!-- 跟进Component -->
<app-follow-up #followUpRef [initParams]="initParams" [ohterParams]="{ type: this.tabsIndex }"></app-follow-up>

<!-- 打款失败 START -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isPaymentVisible"
  nzTitle="打款失败"
  (nzOnCancel)="isPaymentVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <!-- body START -->
      <form nz-form class="form-modal-body" [formGroup]="paymentForm">
        <p class="payment-tips">是否确定要将订单改为打款失败状态？</p>
        <nz-form-item>
          <nz-form-label nzSpan="7" nzRequired>打款失败原因</nz-form-label>
          <nz-form-control nzSpan="17" nzErrorTip="请选择打款失败原因!">
            <nz-select
              nzShowSearch
              nzAllowClear
              nzPlaceHolder="请选择打款失败原因"
              formControlName="note"
              (ngModelChange)="reasonChange($event)">
              <nz-option
                *ngFor="let item of paymentReasons"
                [nzLabel]="item.label"
                [nzValue]="item.label">
              </nz-option>
            </nz-select>
          </nz-form-control>
        </nz-form-item>
      </form>
      <!-- body END -->
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="primary" (click)="subPayment(3)">确定</button>
        <button nz-button nzType="default" (click)="isPaymentVisible = false">取消</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- 打款失败 END -->